<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common/commons.jsp"%>
<%@ include file="/common/meta.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>用户注册</title>
	<script src="${ctx}/js/ajaxutil.js" type="text/javascript"></script>
	<script>
		$(document).ready(function(){
			//聚焦第一个输入框
			$("#loginName").focus();
			//为inputForm注册validate函数
			$("#regist1Form").validate({
				rules: { 
					loginName: { 
        				required: true,
        				minlength:4,
        				remote: "${ctx}/regist!checkLoginName.action?oldLoginName="+encodeURIComponent('${loginName}')
    				},
          			//name: "required",
          			password: {
    					required: true,
    					minlength:3
    				}, 
    				passwordConfirm: {
    					equalTo:"#password"
    				},
    				email: {
    					required:true,
    					email:true
    				},
    				telNumber:"required",
    				forgotQuestion:"required",
    				forgotAnswer:"required"
    				//checkedRoleIds:"required"
				},
				messages: {
					loginName: {
						remote: "用户名已存在"
					},
					passwordConfirm: {
						equalTo: "输入与上面相同的密码"
					},
					email: {
						required: "邮箱必须填写"
					},
					telNumber: {
						required: "联系电话必须填写，可以是座机或手机"
					},
					forgotQuestion: {
						required: "密码提示问题必须填写，这是找回密码的依据"
					},
					forgotAnswer: {
						required: "提示问题答案必须填写"
					}
				}
			});
		});
		
///////////////


	function switchDepList(){
		
		var selval=eval($("#userType").val());
		$("#deptType").empty();
		if(selval<0)
		{
			var content="<option value='-1'>--请选择--</option>";
			$(content).appendTo("#deptType");
			return;		
		}

		if(selval==undefined||selval==null)
			return;
		
		var callback=function (result){
			var content="<option value='-1'>--请选择--</option>";
			result=eval(result);
			$(result).each(function (i) {
				content+="<option value='"+result[i].id+"'>"+result[i].name+"</option>";
			});
			$(content).appendTo("#deptType");
		}
		
		var data={type:selval};
		ajaxRequest("regist!deptJson.action",data,callback);
	}
	
	function validateAllTypes(){
		var types=['userType','deptType','disType'];
		var ret = true;
		for(var i=0;i<types.length;i++){
			if(ret)
			{
				ret = validateAType(types[i]);
			}
			else
			{
				validateAType(types[i]);
			}
		}
		return ret;
	}
	
	function validateAType(elementId){
		var type=$('#'+elementId).val();
		if(eval(type)<0){
			$("#"+elementId+"1").remove();
			$("<label id='"+elementId+"1' class='errorL'>该类型必须选择</label>").insertAfter("#"+elementId);
			return false;
		}else{
			$("#"+elementId+"1").remove();
			return true;
		}
		
	}
	
	function checkUserName(){
		var loginName=$.trim($("#loginName").val());
		if(loginName==""||loginName.length<4)
			return;
		
		var callback=function (result){
			var id="veryidentifyId";
			$("#"+id).remove();
			if(eval(result))
			{
				$("<label id='"+id+"' class='checked'>恭喜，用户名可用！</label>").insertAfter("#loginName");	
			}
			else
			{
				$("<label id='"+id+"' class='errorL'>用户名重复！</label>").insertAfter("#loginName");	
				//$("#loginName").focus();
			}
		};
		
		var data={loginName:loginName};
		ajaxRequest("regist!checkLoginName.action",data,callback);
	}
	function removeLabel(){
		//alert();
		$('#veryidentifyId').remove();
	}
	</script>
	
	<style type="text/css">
		.errorL{
			color: red;
			font-weight: bold;
			background: transparent url(${ctx}/js/validate/images/unchecked.gif) no-repeat scroll 0 0;
			padding-left: 18px;
		}
		.checked {
			background: transparent url(images/checked.gif) no-repeat scroll 0 0;
			padding-left: 18px;
		}
	</style>
</head>

<body>
<h3>填写注册用户基本信息</h3>
<div id="inputDiv">
<form id="regist1Form" action="regist!regist2.action" method="post" >
<input type="hidden" name="id" value="${id}" />

<table class="inputView" width="90%">
	<tr>
		<td width="150px">用户名:</td>
		<td><input type="text" name="loginName" class="inputText" id="loginName" value="${loginName }"  /></td><!-- onkeypress="removeLabel()" onblur="checkUserName()" -->
	</tr>
	<!-- 
	<tr>
		<td>用户名:</td>
		<td><input type="text" name="name" size="40" value="${name}" /></td>
	</tr>
	 -->
	<tr>
		<td>密码:</td>
		<td><input type="password" id="password" name="password" class="inputText" value="${password }" /></td>
	</tr>
	<tr>
		<td>确认密码:</td>
		<td><input type="password" name="passwordConfirm" class="inputText" value="${password }" /></td>
	</tr>
	<tr>
		<td>联系电话:</td>
		<td><input type="text" name="telNumber" class="inputText" value="" /></td>
	</tr>
	<tr>
		<td>电子邮箱:</td>
		<td><input type="text" name="email" class="inputText" value="${email }" /></td>
	</tr>
	  	<tr>
	  		<td>忘记密码提示问题:</td>
	  		<td><input type="text" name="forgotQuestion" class="inputLongText"/></td>
	  	</tr>
	  	<tr>
	  		<td>忘记密码提示问题答案:</td>
	  		<td><input type="text" name="forgotAnswer" class="inputLongText"/></td>
	  	</tr>
	  	<tr>
	  		<td>用户类型:</td>
	  		<td><select name="userType" id="userType" onchange="switchDepList()" class="inputSelect" onblur="validateAType('userType')">
	  			<option value="-1">--请选择--</option>
	  			<option value="0">备案单位</option>
	  			<option value="1">审核单位</option>
	  			</select></td>
	  	</tr>
	  	<tr>
	  		<td>单位类型:</td>
	  		<td>
	  		<select name="deptType" id="deptType" class="inputSelect" onblur="validateAType('deptType')">
	  		<option value="-1">--请选择--</option>
	  		</select>
	  		</td>
	  	</tr>
	  	<tr>
	  		<td colspan="2">
	  		<s:select label="单位区域" list="ctProList" name="disType" listKey="disId" listValue="name" cssClass="inputSelect" onblur="validateAType('disType')"></s:select>
	  		</td>
	  	</tr>
	  	<tr>
	  		<td colspan="2" align="center">
	  		<input type="submit" name="submit" value="下一步"/>
	  		<input type="reset" name="reset" value="重&nbsp;&nbsp;置"/>
	  		<input type="button"  value="取&nbsp;&nbsp;消" onclick="history.back()"/>
	  		</td>
	  	</tr>	
	  	
</table>
</form>
</div>
</body>
</html>